def dfs(V, n, k, A):
    if k >= n:
        print(A)
        return
    for i in range(n):
        if V[i] == 0:
            V[i] = 1
            A[k] = i
            dfs(V, n, k + 1, A)
            V[i] = 0

n = 5
V = [0] * n
A = [0] * n
dfs(V, n, 0, A)
